package com.test.qnews.custom;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.test.qnews.R;

/**
 * Created by dllo on 16/1/9.
 */
public class DayNightMode {
    public final static int THEME_SUN = 1;
    public final static int THEME_NIGHT = 2;

    public static void onActivityCreateSetTheme(Activity activity){
        int theme = getDayNightMode(activity);
        switch (theme){
            case THEME_SUN:
                activity.setTheme(R.style.SunTheme);
                break;
            case THEME_NIGHT:
                activity.setTheme(R.style.NIghtTheme);
                break;
        }
    }

    private static SharedPreferences getSharePreference(Context context){
        return context.getSharedPreferences("NightMOdeDemo",Context.MODE_PRIVATE);
    }

    public static int getDayNightMode(Context context){
        SharedPreferences sharedPreferences = getSharePreference(context);
        return sharedPreferences.getInt("SUN_NIGHT_MODE",THEME_SUN);
    }

    public static void setDayNightMode(Context context,int mode){
        SharedPreferences sharedPreferences = getSharePreference(context);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("SUN_NIGHT_MODE",mode);
        editor.commit();
    }


}
